package com.pass.six;

import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;

/**
 * Pass Six: for q2
 * 
 * calculate # of edges.
 * 
 * Mapper == PassOne Mapper (emit nodes to respective group)
 * 
 * Reducer do spatial join, outputs a line per edge if the edge has at least 1
 * node non-intersection. calculates the # of edges that both nodes are
 * intersection and outputs N/2 lines.
 * 
 * line # == edge # at last.
 * 
 * @author bh349
 */
public class PassSix extends Configured implements Tool {

	public int run(String[] args) throws Exception {
		Job job = new Job(getConf(), "pass 6");
		job.setJarByClass(PassSix.class);
		job.setMapperClass(PassSixMapper.class);
		job.setReducerClass(PassSixReducer.class);
		job.setOutputKeyClass(IntWritable.class);
		job.setOutputValueClass(Text.class);
		FileInputFormat.addInputPaths(job, "pass0");
		FileOutputFormat.setOutputPath(job, new Path("pass6out"));
		return job.waitForCompletion(true) ? 0 : 1;
	}
}
